<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  
  <meta name="generator" content="Hugo 0.98.0" />

  
  <meta name="description" content="走在通往幸福的路上">
  

  
  <link rel="apple-touch-icon" sizes="180x180" href="https://blog.v5u.win/apple-touch-icon.png">

  
  <link rel="icon" type="image/png" sizes="32x32" href="https://blog.v5u.win/favicon-32x32.png">

  
  <link rel="icon" type="image/png" sizes="16x16" href="https://blog.v5u.win/favicon-16x16.png">

  
  <link rel="manifest" href="https://blog.v5u.win/site.webmanifest">

  
  <link rel="mask-icon" href="https://blog.v5u.win/safari-pinned-tab.svg" color="">

  <meta name="msapplication-TileColor" content="">

  <meta name="theme-color" content="">

  
  <link rel="stylesheet" href="https://blog.v5u.win/css/bootstrap.min.css" />

  
  <title>RN教程 | 为吾优</title>
  

  <style>
body {
  min-width: 300px;
}

.custom-navbar {
  margin-bottom: 1em;
  height: 60px;
}

.custom-navbar a {
  display: inline-block; 
  padding: 18px 0;
  margin-right: 1em; 
  font-weight: bold; 
}

.custom-navbar a:hover,
.custom-navbar a:focus {
  text-decoration: none; 
}

@media print {
  .custom-navbar {
    display: none;
  }
}

article {
  padding-bottom: 1em;
}

img {
  max-width: 100%;
}


body {
  background-color: #fff;
}



body {
  color: #212529;
}



a {
  color: #007bff;
}



a:hover,
a:focus {
  color: #0056b3;
}



.custom-navbar {
  background-color: #212529;
}



.custom-navbar a {
  color: rgba(255,255,255,.75);
}



.custom-navbar a:hover,
.custom-navbar a:focus {
  color: rgba(255,255,255,1);
}



.container {
  max-width: 800px;
}





</style>
</head>

<body>
  <nav class="custom-navbar">
  <div class="container">
    
    <a href="/">文章</a>
    
    <a href="/tags/">标签</a>
    
    <a href="/about/">关于</a>
    
    <a href="/index.xml">RSS</a>
    
  </div>
</nav>
  
  <div class="container">
    <article>
      <h1>RN教程</h1>
<p>[TOC]</p>
<h2 id="搭建开发环境">搭建开发环境</h2>
<p>安装依赖
iOS
必须安装的依赖有：Node、Watchman、Xcode 和 CocoaPods。
安卓
必须安装的依赖有：Node、Watchman、JDK 和 Android Studio。</p>
<p>最佳实践：使用以下方式创建新项目</p>
<p>create-react-native-app demo0 设置创建项目的可选项
启动</p>
<pre tabindex="0"><code>- yarn android
- yarn ios
- yarn web
</code></pre><p>接口环境配置：</p>
<p>使用青花瓷抓包工具</p>
<p>配置：Proxy-》Mac OS proxy  监听本机代理</p>
<p>tools-&gt; map remote 设置允许，添加远程端口映射,或者 map local做本地文件映射</p>
<p>配置测试机 的IP代理</p>
<h2 id="创建项目">创建项目</h2>
<pre tabindex="0"><code>npx react-native init AwesomeProject
或
create-react-native-app demoName
这种方式创建的项目有iOS Android web 三端 最佳实践
</code></pre><h2 id="编译并运行-react-native-应用">编译并运行 React Native 应用</h2>
<pre tabindex="0"><code>yarn ios # 或者 yarn react-native run-ios
yarn android
yarn web
</code></pre><h2 id="reload">reload</h2>
<p>iOS： cmd+r</p>
<p>安卓: cmd+m</p>
<pre tabindex="0"><code>brew install node
brew install watchman
# 使用nrm工具切换淘宝源
npx nrm use taobao
npm install -g yarn// Yarn是 Facebook 提供的替代 npm 的工具，可以加速 node 模块的下载。
brew install cocoapods

---
npm install -g expo-cli
npm install -g create-react-native-app 
</code></pre><p>验证 metro 是否启动 访问https://127.0.0.1:8081 可以正常响应</p>
<h3 id="矢量图使用">矢量图使用</h3>
<p>引入node包</p>
<p>yarn add react-native-vector-icons</p>
<p>将react-native-vector-icons/Fonts 引入xcode</p>
<p>修改info.plist 加入字体包</p>
<pre tabindex="0"><code>&lt;key&gt;UIAppFonts&lt;/key&gt;
    &lt;array&gt;
      &lt;string&gt;Entypo.ttf&lt;/string&gt;
      &lt;string&gt;EvilIcons.ttf&lt;/string&gt;
      &lt;string&gt;FontAwesome.ttf&lt;/string&gt;
      &lt;string&gt;Foundation.ttf&lt;/string&gt;
      &lt;string&gt;Ionicons.ttf&lt;/string&gt;
      &lt;string&gt;MaterialIcons.ttf&lt;/string&gt;
      &lt;string&gt;Octicons.ttf&lt;/string&gt;
      &lt;string&gt;SimpleLineIcons.ttf&lt;/string&gt;
      &lt;string&gt;Zocial.ttf&lt;/string&gt;
      &lt;string&gt;MaterialCommunityIcons.ttf&lt;/string&gt;
    &lt;/array&gt;
</code></pre><p>pod update</p>
<p>file-&gt; workspace setting-&gt;legacy build system</p>
<p>build setting-&gt;library search paths-&gt; CocoaAsyncSocket-&gt;修改寻找方式recursive</p>
<p>修改pod包bug</p>
<p>React Navigation 4 API</p>
<pre tabindex="0"><code>const MineStack = createStackNavigator({
  Mine: MineScreen,
  Detail: DetailsScreen,
  Setting: SettingSrceen
});
</code></pre><h2 id="安卓开发">安卓开发</h2>
<p>api请求失败是因为本地通过localhost访问，iOS模拟器正常，安卓模拟器异常。</p>
<p>需要改为通过本机ip访问在header中添加host字段</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-js" data-lang="js"><span style="display:flex;"><span> <span style="color:#66d9ef">var</span> <span style="color:#a6e22e">url</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;http://192.168.0.5/index.php/api/index&#39;</span>;
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">fetch</span>(<span style="color:#a6e22e">url</span>, {
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">method</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;GET&#39;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">headers</span><span style="color:#f92672">:</span> {
</span></span><span style="display:flex;"><span>            <span style="color:#e6db74">&#39;Accept&#39;</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;application/json&#39;</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#e6db74">&#39;Content-Type&#39;</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;application/json;charset=utf-8&#39;</span>, <span style="color:#75715e">//数据格式 json或者key-value形式
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>            <span style="color:#e6db74">&#34;Connection&#34;</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#34;close&#34;</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#e6db74">&#39;Host&#39;</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;000.com&#39;</span>,
</span></span><span style="display:flex;"><span>        },
</span></span><span style="display:flex;"><span>    })
</span></span></code></pre></div><p>&ldquo;Connection&rdquo;: &ldquo;close&rdquo;,iOS为close 安卓默认为 keep-alive</p>
<p>请求的服务器地址是本地的环境的不行，必须线上才可以，这是android问题，ios正常</p>
<p>最后解决的方法是用安卓手机usb调试，然后没有连wifi连的是自己的4g网络，就不报这样的错误了，接口用的是线上的http，没有用https，用的是fetch传formData的数据，</p>
<h2 id="bind">bind</h2>
<p>this.back.bind(this)，我back就是一个方法为啥还要再bind(this). 其实就是一个作用域，绑定这个作用域中的方法。</p>
<p>那么其实我们有两种写法去定义onPress的响应方法。
1.不加bind（this）</p>
<pre tabindex="0"><code>onPress={this.back}
....
  back = () =&gt; {
        const {navigator} = this.props;
        navigator.pop();
    }
</code></pre><p>这种写法不用去bind了，</p>
<p>()=&gt;{} 这种形式的代码，语法规定就是(function(){}).bind(this),即自动添加了bind this</p>
<p>2.需要加bind</p>
<pre tabindex="0"><code>onPress={this.back.bind(this)}

....

  back() {
        const {navigator} = this.props;
        navigator.pop();
    }
</code></pre><h2 id="web和rn交互数据传递">web和RN交互，数据传递</h2>
<h3 id="将rn变量传入web">将RN变量传入Web</h3>
<p>webview 使用的库是 react-native-webview ，在RN 0.60之前 通过onMessage方法传递交互，具体不细讲。因为已经过时了。0.60之后 官方发现还是直接插入js代码更好用injectedJavaScript，所以最佳实践是这样的：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-react" data-lang="react"><span style="display:flex;"><span><span style="color:#75715e">// class中
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// 注入一个方法并绑定给 window.launchScan 以备 RN 调用
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>    <span style="color:#a6e22e">getInjectedJS</span> <span style="color:#f92672">=</span> () =&gt; {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">token</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">token</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">projectId</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;456&#39;</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> <span style="color:#e6db74">`
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">                window.token = &#39;</span><span style="color:#e6db74">${</span><span style="color:#a6e22e">token</span><span style="color:#e6db74">}</span><span style="color:#e6db74">&#39;;// 用window将token声明成全局
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">                token2 = &#39;</span><span style="color:#e6db74">${</span><span style="color:#a6e22e">token</span><span style="color:#e6db74">}</span><span style="color:#e6db74">&#39;; 
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">                window.projectId = &#39;</span><span style="color:#e6db74">${</span><span style="color:#a6e22e">projectId</span><span style="color:#e6db74">}</span><span style="color:#e6db74">&#39;;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">                function btnClick(){
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">                  alert(window.token)
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">                }
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">                `</span>
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>&lt;<span style="color:#f92672">WebView</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">style</span><span style="color:#f92672">=</span>{{ <span style="color:#a6e22e">width</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">width</span>, <span style="color:#a6e22e">height</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">height</span> }}
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">source </span><span style="color:#f92672">=</span> {{<span style="color:#a6e22e">uri</span><span style="color:#f92672">:</span> <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">state</span>.<span style="color:#a6e22e">url</span>}}
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">onLoadProgress</span><span style="color:#f92672">=</span>{({<span style="color:#a6e22e">nativeEvent</span>}) =&gt; <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">setState</span>(
</span></span><span style="display:flex;"><span>      {<span style="color:#a6e22e">progress</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">nativeEvent</span>.<span style="color:#a6e22e">progress</span>}
</span></span><span style="display:flex;"><span>    )}
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">bounces</span><span style="color:#f92672">=</span>{<span style="color:#66d9ef">false</span>}
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">allowFileAccess</span><span style="color:#f92672">=</span>{<span style="color:#66d9ef">true</span>}<span style="color:#960050;background-color:#1e0010">//</span><span style="color:#a6e22e">是否允许访问系统文件</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">javaScriptEnabled</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">ref</span><span style="color:#f92672">=</span>{(<span style="color:#a6e22e">webView</span>) =&gt; {<span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">webView</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">webView</span>}}
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">domStorageEnabled</span><span style="color:#f92672">=</span>{<span style="color:#66d9ef">false</span>}
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">onMessage</span><span style="color:#f92672">=</span>{<span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">onMessage</span>.<span style="color:#a6e22e">bind</span>(<span style="color:#66d9ef">this</span>)}
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">injectedJavaScript</span><span style="color:#f92672">=</span>{<span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">getInjectedJS</span>()} <span style="color:#960050;background-color:#1e0010">//</span> <span style="color:#960050;background-color:#1e0010">**</span> <span style="color:#a6e22e">注意</span><span style="color:#960050;background-color:#1e0010">：</span><span style="color:#a6e22e">这里是重点</span> <span style="color:#960050;background-color:#1e0010">**</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#960050;background-color:#1e0010">//</span> <span style="color:#a6e22e">onLoad</span><span style="color:#f92672">=</span>{<span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">webViewload</span>.<span style="color:#a6e22e">bind</span>(<span style="color:#66d9ef">this</span>)}
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">onLoadEnd</span><span style="color:#f92672">=</span>{<span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">onLoadEnd</span>.<span style="color:#a6e22e">bind</span>(<span style="color:#66d9ef">this</span>)}
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">onError</span><span style="color:#f92672">=</span>{<span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">onError</span>}
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">renderError</span><span style="color:#f92672">=</span>{<span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">renderError</span>}
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">onNavigationStateChange</span><span style="color:#f92672">=</span>{<span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">onNavigationStateChange</span>.<span style="color:#a6e22e">bind</span>(<span style="color:#66d9ef">this</span>)}
</span></span><span style="display:flex;"><span>/&gt;
</span></span></code></pre></div><p>js 字符串将会插入到web的scripts标签中，当做正常的js代码执行。</p>
<h2 id="打包">打包</h2>
<h3 id="ios">iOS</h3>
<pre tabindex="0"><code>先创建ios/bundle目录
npx react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/bundle/index.ios.bundle --assets-dest ios/bundle
</code></pre><p>注销application中的debug条件代码</p>
<p>将资源文件assets+ios.bundle加到项目中，直接可以编译通过的话就可以打包了</p>
<p>node编译报错</p>
<p>解决：build phases-&gt;buildle rn image
使用了非标准的 nodejs 安装流程</p>
<pre tabindex="0"><code>如果你使用了非标准的 nodejs 安装流程，
在Xcode中选择Project -&gt; Build Phases -&gt; Bundle React Native code and images，
把NODE_BINARY改为node可执行文件的绝对路径
你可以在终端命令行中执行 `$ which node` 来查看你当前node的绝对路径
export NODE_BINARY=/Users/fanjinlong/.nvm/versions/node/v12.9.0/bin/node
../node_modules/react-native/scripts/react-native-xcode.sh
</code></pre><p>打包失败</p>
<p>yarn start &ndash;reset-cache</p>
<h3 id="android">Android</h3>
<ol>
<li>
<p>生成index.android.bundle 文件在src/main/assets/目录下</p>
</li>
<li>
<p>修改配置: 编译平台，去除debug代码，添加权限配置等</p>
</li>
<li>
<p>生成签名，编译release包： build -&gt; genero signed build apk</p>
</li>
<li>
<p>as编译打包，或命令行打包</p>
</li>
</ol>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span>也可以as生成，下面是命令行生成
</span></span><span style="display:flex;"><span>keytool -genkey -alias my-release-key.keystore -keyalg RSA -validity <span style="color:#ae81ff">20000</span> -keystore my-release-key.keystore
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>// release.keystore 签名需要放到 android/app/build/ ，可以不放，使用Androidstudio 打包时指定文件路径就行
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>查看keystore 信息
</span></span><span style="display:flex;"><span>keytool -v -list -keystore my-release-key.keystore
</span></span></code></pre></div><h4 id="安卓打包改配置">安卓打包改配置</h4>
<p>APP displayName：android/app/src/main/res/values/strings.xml app_name</p>
<p>APP logo: res/mipmap rpx命令编译失败，不能用</p>
<p>增加签名证书，修改 android/app/gradle.properties</p>
<pre tabindex="0"><code># Version of flipper SDK to use with React Native
FLIPPER_VERSION=0.33.1
# 新加:
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=com.suipingbang.www
MYAPP_RELEASE_STORE_PASSWORD=111111
MYAPP_RELEASE_KEY_PASSWORD=111111
</code></pre><p>修改android/app/build.gradle(app)</p>
<pre tabindex="0"><code>android{
...
  signingConfigs {
      release {
            if (project.hasProperty(&#39;MYAPP_RELEASE_STORE_FILE&#39;)) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
}
</code></pre><p>更改<code>build.gradle</code> 文件中的 <code>applicationId</code> 属性 应用ID</p>
<p>rn命令行编译js代码-&gt;bundle资源束，有js map和没有，在项目目录下。</p>
<pre tabindex="0"><code>npx react-native bundle --platform android --dev false --reset-cache --entry-file index.js --bundle-output ./android/app/build/generated/assets/react/release/index.android.bundle --assets-dest android/app/build/generated/res/react/release --sourcemap-output android/app/build/generated/sourcemaps/react/release/index.android.bundle.map
</code></pre><pre tabindex="0"><code>npx react-native bundle --platform android --dev false --reset-cache --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
</code></pre><p>bundle可能会导出失败，由于没有目录，所以需要在android/app/src/main目录下创建assets目录
def enableSeparateBuildPerCPUArchitecture = true 设置为true根据CPU生成不通的apk包</p>
<h4 id="打包-apk在androidappbuildoutputsapk-生成app-releaseapk">打包 apk（在android/app/build/outputs/apk 生成app-release.apk）</h4>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span>cd android 
</span></span><span style="display:flex;"><span>./gradlew clean <span style="color:#f92672">&amp;&amp;</span> ./gradlew assembleRelease 该打包方式遇到问题,后来也成功了
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>在设备上安装release版本
</span></span><span style="display:flex;"><span>npx react-native run-android --variant<span style="color:#f92672">=</span>release 这个成功
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>AndroidStudio 打包
</span></span><span style="display:flex;"><span>build/Generate Signed Bundle or APK -&gt; APK -&gt; 配置keystores -&gt; 选择release， V1 V2两个都要勾选
</span></span></code></pre></div><p><code>app -&gt;release-&gt;app-release.apk</code> &ndash;&gt; android studio 打包apk发布包 文件存放路径：</p>
<p><code>app/build/outputs/apk/release/app-release.apk</code> &ndash;&gt; npx命令行输出目录：</p>
<p>Metro js 打包热更新,用于开发，起下发js代码的server，编译打包时坑了我。apk闪退。</p>
<p>如果是 react-native 0.6+ 每次 yarn / npm install 之后需要先运行 <code>npx jetify</code>检查一遍。</p>
<p>使用AS4 IDE打包release 不行，启动直接崩溃。只能使用npx。两者的apk输出目录不是同一个地方！</p>
<p>参考https://juejin.im/post/5dc8c080f265da4cf022ddc6</p>
<h3 id="react-native-相关的-activity-和-application">React Native 相关的 Activity 和 Application</h3>
<p>创建一个继承自 <code>com.facebook.react.ReactActivity</code> 的 Activity</p>
<p><strong>重写 <code>getMainComponentName()</code> 方法，返回的字符串必须和前面的 <code>AppRegistry.registerComponent('navigation', () =&gt; App)</code> 里的 <code>navigation</code> 对应，表示该 Activity 会显示对应组件里的内容。</strong></p>
<h3 id="android-1">Android</h3>
<p>编辑 <code>android/app/src/main/res/values/strings.xml</code> 文件：</p>
<h3 id="ios-1">iOS</h3>
<p>编辑 <code>ios/test/Info.plist</code> 文件：</p>
<h5 id="android启动图标更换后部分手机未生效解决办法">Android启动图标更换后部分手机未生效解决办法</h5>
<p>1、方法一：clean项目，下载应用，重新手机，重新安装
2、方法二：修改手机主题（马上生效，但是VIVO手机出现再次切换原主题恢复原图标问题）
3、方法三：重命名启动图标名称，重新运行安装项目即可（最佳方案）
4、方法四：更改应用版本号</p>
<p>可能原因：手机上有缓存，不是app内部缓存，而是launcher缓存。</p>
<h3 id="上架">上架</h3>
<p>软著如何统计代码行数？</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span><span style="color:#75715e"># 统计当前目录下的 app 文件夹中，所有 JS 文件的代码行数</span>
</span></span><span style="display:flex;"><span>find ./app <span style="color:#e6db74">&#34;(&#34;</span> -name <span style="color:#e6db74">&#34;*.js&#34;</span> <span style="color:#e6db74">&#34;)&#34;</span> -print | xargs wc -l
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 统计当前目录下的 ios 文件夹中，所有 Objective-C 的代码行数</span>
</span></span><span style="display:flex;"><span>find ./ios <span style="color:#e6db74">&#34;(&#34;</span> -name <span style="color:#e6db74">&#34;*.h&#34;</span> -or -name <span style="color:#e6db74">&#34;*.m&#34;</span> <span style="color:#e6db74">&#34;)&#34;</span> -print | xargs wc -l
</span></span><span style="display:flex;"><span><span style="color:#75715e">#统计当前目录下的 android 文件夹中，所有 Java 的代码行数</span>
</span></span><span style="display:flex;"><span>find ./android <span style="color:#e6db74">&#34;(&#34;</span> -name <span style="color:#e6db74">&#34;*.java&#34;</span> <span style="color:#e6db74">&#34;)&#34;</span> -print | xargs wc -l
</span></span></code></pre></div>
    </article>
  </div>

  
  
  

  
</body>

</html>